package ajax;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.json.annotations.JSON;

import net.sf.json.JSONObject;

import com.opensymphony.xwork2.ActionSupport;

public class AjaxAction extends ActionSupport {

	// 用户Ajax返回数据  
    private String result;   
	
    private String loginName;   

    private String password;
    
    private Map map;
    
	@Override
	public String execute() throws Exception {

		// 用一个Map做例子   
        Map<String, String> map = new HashMap<String, String>();   
  
        // 为map添加一条数据，记录一下页面传过来loginName   
        map.put("name", this.loginName);   
  
        // 将要返回的map对象进行json处理   
//        JSONObject jo = JSONObject.fromObject(map);   
  
        // 调用json对象的toString方法转换为字符串然后赋值给result   
//        this.result = jo.toString();  
//        List<Object> list = (List<Object>) JSONObject.toBean(jo);
  
        // 可以测试一下result   
//        System.out.println(this.result);   
  
        this.map = map;
        return SUCCESS;   

	}
	
	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getLoginName() {
		return loginName;
	}
	
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}

	public Map getMap() {
		return map;
	}

	public void setMap(Map map) {
		this.map = map;
	}
}
